programming4us
           
 
 
Programming

Microsoft ASP.NET 4 : Ajax - Extender Controls (part 2) - A Modal Pop-up Dialog-Style Component

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
4/24/2012 3:25:09 PM

2. A Modal Pop-up Dialog-Style Component

AJAX provides another interesting feature that makes Web applications appear more like desktop applications: the ModalPopup extender. Historically, navigating a Web site involves users walking down the hierarchy of a Web site and climbing back out. When users provide inputs as they work with a page, the only means available to give feedback about the quality of the input data has been the validation controls. In addition, standard Web pages have no facility to focus users' attention while they type in information.

Traditional desktop applications usually employ modal dialog boxes to focus user attention when gathering important information from the end user. The model is very simple and elegant: The end user is presented with a situation in which he or she must enter some data and then click OK or Cancel before moving on. After dismissing the dialog box, the end user sees exactly the same screen he or she saw right before the dialog box appeared. There's no ambiguity and no involved process where the end user must walk up and down some arbitrary page hierarchy.

This example shows how to use the pop-up dialog extender control. You create a page with some standard content and then have a modal dialog-style pop-up window appear right before the page is submitted.

Using a ModalPopup extender

  1. Add a new page to AJAXORama to host the pop-up extender. Call it UseModalPopupExtender.

  2. As with all the other examples using AJAX controls, drag a ScriptManager from the Toolbox onto the page.

  3. Add a title to the page (the example here uses "ASP.NET Code of Content"). Give the banner some prominence by surrounding it with <h1> and </h1> tags. You can simply replace the existing <div> tag with the <h1> tag.

  4. Drag a Panel from the Toolbox onto the page to hold the page's normal content.

  5. Add a Button to the Panel for submitting the content. Give the Button the ID ButtonSubmit and the text Submit and create a button Click event handler. You need this button later.

  6. Place some content on the panel. The content in this sample application uses several check boxes that the modal dialog pop-up examines before the page is submitted.

    <h1 >ASP.NET Code Of Conduct </h1>
    
    <asp:Panel ID="Panel1" runat="server"
        style="z-index: 1;left: 10px;top: 70px;
        position: absolute;height: 213px;width: 724px;
        margin-bottom: 0px;">
    <asp:Label ID="Label1" runat="server"
           Text="Name of Developer:"></asp:Label>
           &nbsp;<asp:TextBox ID="TextBox1"
           runat="server"></asp:TextBox>
    
    <br />
    <br />
    <br />
    As an ASP.NET developer, I promise to
    <br />
    <input type="checkbox" name="Check" id="Checkbox1"/>
    <label for="Check1">Use Forms Authentication</label>
    <br />
    <input type="checkbox" name="Check" id="Checkbox2"/>
    <label for="Check2">Separate UI From Code</label>
    <br />
    <input type="checkbox" name="Check" id="Checkbox3"/>
    <label for="Check3">Take Advantage of Custom Controls</label>
    <br />
    <input type="checkbox" name="Check" id="Checkbox4"/>
    <label for="Check4">Use AJAX</label>
    <br />
    <input type="checkbox" name="Check" id="Checkbox5"/>
    <label for="Check5">Give MVC a try</label>
    <br />
    <input type="checkbox" name="Check" id="Checkbox6"/>
    <label for="Check6">Give Silverlight a try</label>
    <br />
    
    <asp:Button ID="ButtonSubmit" runat="server" Text="Submit"
            onclick="ButtonSubmit_Click" />
    <br />
    </asp:Panel>
    
    					  

  7. Add another Panel to the page to represent the pop-up. Give this Panel a light yellow background color so that you'll be able to see it when it comes up. It should also have the ID PanelModalPopup.

  8. Add some content to the new Panel that's going to serve as the modal pop-up. At the very least, the pop-up should have OK and Cancel buttons. Give the OK and Cancel buttons the ID values ButtonOK and ButtonCancel. You need them a bit later, too.

    <asp:Panel ID="PanelModalPopup" runat="server"
        BorderColor="Black"
        BorderStyle="Solid"
        BackColor="LightYellow" Height="72px"
        Width="403px">
        <br />
        <asp:Label
           Text="Are you sure these are the correct entries?"
           runat="server">
        </asp:Label>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Button ID="ButtonOK"
           runat="server"
           Text="OK" />
        &nbsp;&nbsp;
        <asp:Button ID="ButtonCancel"
        runat="server" Text="Cancel" />
        <br />
    </asp:Panel>

  9. Add a script block to the ASPX file. You need to do this by hand. Write functions to handle the OK and Cancel buttons. The example here examines check boxes to see which ones have been selected and then displays an alert to show which features have been chosen. The Cancel handler simply displays an alert indicating that the Cancel button was clicked:

    <script type="text/javascript">
    
        function onOk() {
            var optionsChosen;
            optionsChosen = "Options chosen: ";
    
            if($get('Checkbox1').checked)
            {
              optionsChosen =
                 optionsChosen.toString() +
                 "Use Forms Authentication ";
            }
    
            if($get('Checkbox2').checked)
            {
              optionsChosen =
                 optionsChosen.toString() +
                 "Separate UI From Code ";
            }
    
            if($get('Checkbox3').checked)
            {
              optionsChosen =
                 optionsChosen.toString() +
                 "Take Advantage of Custom Controls ";
            }
    
            if($get('Checkbox4').checked)
            {
              optionsChosen =
                 optionsChosen.toString() +
                 "Give AJAX a try ";
            }
            alert(optionsChosen);
        }
    
        function onCancel() {
           alert("Cancel was pressed");
        }
    </script>
    
    					  

  10. Drag the ModalPopup extender from the Toolbox onto the page.

  11. Add the following markup to the page to set various properties on the new ModalPopup extenders.s This sets the OkControIID property to ButtonOK and the CancelControlID property to ButtonCancel. It also sets the OnCancelScript property to onCancel() (the client-side Cancel script handler you just wrote). Set OnOkScript="onOk()" (the client-side OK script handler you just wrote). Finally, the following markup sets the TargetControlID property to ButtonSubmit:

    <cc1:ModalPopupExtender
        ID="ModalPopupExtender1"
        runat="server"
        OkControlID="ButtonOK"
        CancelControlID="ButtonCancel"
        OnCancelScript="onCancel()"
        OnOkScript="onOk()"
        TargetControlID="ButtonSubmit"
        PopupControlID="PanelModalPopup"
        runat="server"
        DynamicServicePath="" Enabled="True">
    </cc1:ModalPopupExtender>

    This graphic shows the layout of the page using the ModalPopup extender in Visual Studio 2010:



  12. Run the page. When you click the Submit button, the Panel designated to be the modal pop-up window is activated. (Remember, the Submit button is the TargetControlID of the ModalPopup Extender.) When you dismiss the pop-up window by clicking OK or Cancel, you should see the client-side scripts being executed. The following graphic image shows the ModalPopup extender displaying the modal pop-up window:


Other -----------------
- Mobile Handheld Devices : DATA SYNCHRONIZATION
- Mobile Handheld Devices : MEMORY, STORAGE AND BATTERIES
- LINQ to Objects : How to Return Elements When the Result Is a Sequence (Select Many)
- LINQ to Objects : How to Change the Return Type (Select Projection)
- A Technical Overview of the Mobile Web : OTHER MOBILE TECHNOLOGIES
- A Technical Overview of the Mobile Web : THE MOBILE NETWORK
- Programming WCF Services : The Response Service (part 4) - Transactions
- Programming WCF Services : The Response Service (part 3) - Queued Service-Side Programming & Response Service-Side Programming
- Programming WCF Services : The Response Service (part 2) - Client-Side Programming
- Programming WCF Services : The Response Service (part 1) - Designing a Response Service Contract
- Programming WCF Services : Queued Versus Connected Calls - Requiring Queuing
- Programming WCF Services : Queued Services - Playback Failures
- DotNetNuke Skinning : Package and Deploy
- Unit Testing in Visual Studio 2010 (part 2) - Running a battery of tests
- Unit Testing in Visual Studio 2010 (part 1) - Creating unit tests
- Microsoft ASP.NET 3.5 : AJAX-Enabled Web Services - Remote Calls via Page Methods
- Microsoft ASP.NET 3.5 : WCF Services for ASP.NET AJAX Applications
- Mobile Game Networking Essentials : Network Programming and J2ME
- Mobile Game Networking Essentials : Multiplayer Game Basics & Network Game Problems and Solutions
- Software Testing with Visual Studio Team System 2008 : Debug and running web test (part 2) - Running the test
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us